<%@ page import="entry.Book" %>
<%@ page import="java.util.ArrayList" %><%--
  Created by IntelliJ IDEA.
  User: 86151
  Date: 2024/08/14
  Time: 22:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>图书管理系统</title>
    <%
        String base = request.getContextPath() + "/";
        String url = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + base;
    %>
    <base href="<%=url%>">
    <script type="text/javascript" src="js/jquery-1.8.3.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $.get("book/queryBybook", function (ph) {
                alert(ph)
                JSON.stringify(ph);
                x(ph.list);
                showBut(ph);
            });
            //查询按钮单击后发送异步请求
            $("[type='button']").click(function () {
                //获得下拉列表的value值
                var index = $("select").val();
                var str = $("[name='kk']").val();
                $.get("book/queryBybook", {"query": index, "str": str}, function (ph) {
                    JSON.stringify(ph);
                    x(ph.list);
                    showBut(ph);
                });
            });
        });
        $(document).on("click", "a[title='删除']", function () {
            var bookId = $(this).attr("name");
            $.get("book/deleteBook", {"bookId": bookId}, function (obj) {
                JSON.stringify(obj);
                alert(obj.mess);
                x(obj.books.list);
                showBut(obj.books);
            });
        });
        $(document).on("click", "a[title!='删除']", function () {
            var bookId = $(this).attr("name");
            window.location.href = "updaBook.jsp?bookId=" + bookId;
            //$.get("updaBook.jsp",{"bookId":bookId});
        });

        function x(books) {
            $("tbody").empty();
            for (var i = 0; i < books.length; i++) {
                $("<tr>" +
                    "<td>" + books[i].bookName + "</td>" +
                    "<td>" + books[i].bookAuthor + "</td>" +
                    "<td>" + books[i].bookPublish + "</td>" +
                    "<td>" + books[i].bookPage + "</td>" +
                    "<td>" + books[i].bookPrice + "</td>" +
                    "<td>" + books[i].createDate + "</td>" +
                    "<td><a name='" + books[i].bookId + "' title='删除'>删除</a><a name='" + books[i].bookId + "'>修改</a></td>" +
                    "</tr>").appendTo("tbody");
            }
        }

        //根据PageHelper对象动态获得分页按钮
        function showBut(ph) {
            $("div").empty();
            if (ph.indexPage != 1) {
                $("<input type='button' value='首页' name='1'/>").appendTo("div");
                $("<input type='button' value='上一页' name='" + (ph.indexPage - 1) + "'/>").appendTo("div");
            }
            if (ph.indexPage != ph.countPage) {
                $("<input type='button' value='下一页' name='" + (ph.indexPage + 1) + "'/>").appendTo("div");
                $("<input type='button' value='尾页' name='" + ph.countPage + "'/>").appendTo("div");
            }
        }

        //为分页按钮绑定单击时间
        $(document).on("click", "[type='button'][value!='查找']", function () {
            var index = $("select").val();
            var str = $("[name='kk']").val();
            var pageindex = $(this).attr("name");
            $.get("book/queryBybook", {"query": index, "str": str, "pageindex": pageindex}, function (ph) {
                JSON.stringify(ph);
                x(ph.list);
                showBut(ph);
            });
        });
    </script>
</head>
<body>
<select name="qq">
    <option value="1">书名</option>
    <option value="2">作者</option>
    <option value="3">出版社</option>
</select>
<input type="text" name="kk"/>
<input type="button" value="查找"/>
<a href="insertbook.jsp">新增图书</a>
<a href="deletebook.jsp">删除图书</a>
<a href="updatebook.jsp">更改图书</a>

<table border="1px">
    <thead>
    <tr bgcolor="#8b0000">
        <td>书名</td>
        <td>作者</td>
        <td>出版社</td>
        <td>页数</td>
        <td>价格</td>
        <td>添加时间</td>
        <td>操作</td>
    </tr>
    </thead>
    <tbody>

    </tbody>
</table>
<div>

</div>

</body>
</html>
